package com.dq.Week3.day12.list;

import java.io.FileNotFoundException;
import java.util.ArrayList;
import java.util.List;
import java.util.Random;

public class ArtShowServiceImpl implements ArtShowService{

    private List<ArtShow> data = ArtShowUtils.creatList();


    public ArtShowServiceImpl() throws FileNotFoundException {
    }


    @Override
    public boolean addArtShow(String studentName) {

        ArtShow newMember = new ArtShow(studentName,null,0,1);
        data.add(newMember);
        return true;
    }

    @Override
    public String pickStudent() {
        //建立对象
        ArtShow artShow = new ArtShow();
        Random random = new Random();
        //循环次数
        int number = 0;
        //下标
        int index = random.nextInt(data.size());
        //开始遍历
        for (ArtShow result : data) {

            if(number==index)
            {
                artShow = result;
            }
            number++;
        }
        String name = artShow.getStuName();


        return name;
    }

    @Override
    public boolean updateArtShow(ArtShow artShow) {
        int index=0;
        for (ArtShow artShow1 : data) {
            if(artShow1.getStuName().equals(artShow.getStuName()))
            {
               data.set(index,artShow);
               return true;
            }
            index++;
        }

        return false;

    }

    @Override
    public List<ArtShow> getAll() {

        return data;//感觉有点慌
    }

    @Override
    public List<String> getNoShowNames() {
        List<String> list = new ArrayList<>();
        for (ArtShow a : data) {
            if(a.getStatus()==0)
            {
                list.add(a.getStuName());

            }
        }
        return list;
    }
}
